package com.maimao.spider.task;

import com.maimao.spider.pipeline.CategoryPipeline;
import com.maimao.spider.processor.CategoryProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Spider;

import java.util.ArrayList;
import java.util.List;

/**
 * @author MaoLin Wang
 * @date 2019/11/2421:19
 */
@Component
public class CategoryTask {

    public static final String url="http://localhost:63342/day01/selectAll.html?_ijt=t774h9850ssbjrvrs3ilhl2nua";
    @Autowired
    private CategoryProcessor categoryProcessor;
    @Autowired
    private CategoryPipeline categoryPipeline;
    public static final List<String> all=new ArrayList<String>(18){{
        for (int i = 0; i < 18; i++) {
            add(url+"?a="+i);
        }
    }};

    //    @Scheduled(cron = "0 52 23 * * ?")
//    @Async("scheduleAsyncExecutor")
    public void spideCate(){
        System.out.println("爬取分类");
        Spider spider=Spider.create(categoryProcessor);
         spider.addUrl(url)
                .addPipeline(categoryPipeline)
                .start();
    }
}
